package com.atguigu.edubanners.controller.front;


import com.atguigu.commonutils.R;
import com.atguigu.edubanners.entity.FrontBanner;
import com.atguigu.edubanners.entity.vo.BannerRequestVo;
import com.atguigu.edubanners.service.FrontBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuanglijiao
 * @since 2021-10-19
 */
@Api(description = "前台bannber显示")
@RestController
@RequestMapping("/edubanners/bannerfront")
@CrossOrigin
public class FrontBannerController {

    @Autowired
    private FrontBannerService bannerService;

    //1.查询所有banner
    @ApiOperation("获取全部banner")
    @GetMapping("getAllFrontBanner")
    public R getAllBanner() {
        List<FrontBanner> list = bannerService.getAllFrontBanner();
        return R.ok().data("list", list);
    }

    //2.前台轮播图列表
    @ApiOperation("前台轮播图列表")
    @GetMapping("getFrontAllBannerLimit5")
    public R getFrontAllBanner() {
        List<FrontBanner> list = bannerService.getFrontAllBannerLimit5();
        return R.ok().data("list", list);
    }

    //3.修改轮播图排序
    @ApiOperation("修改轮播图排序")
    @PostMapping("ModifyFrontBannerSort")
    public R ModifyFrontBannerSort(@RequestBody BannerRequestVo.ModifyFrontBannerSort modifyFrontBannerSort) {
        Boolean b = bannerService.ModifyFrontBannerSort(modifyFrontBannerSort);
        if (b) {
            return R.ok();
        } else {
            return R.error();
        }
    }

}

